<?php

namespace Apps\AppApi\Method\Activity;
use Apps\AppApi\Method\BaseMethod;
use Apps\Common\Models\Activity;
use PhalconPlus\Api\Common\ResultStatus;


/**
 * 活动列表，可通过分类筛选
 * @package Apps\AppApi\Method\Activity
 */
class indexlist extends BaseMethod
{
    /**
     * @var \Apps\Common\Models\Activity array
     */
    private $activity = [];

    public function run()
    {
    	$city_code = $this->getDataItem('citycode',0);
    	$cityId = $this->getCityId($city_code);
    	if($cityId <= 0) {
    		//return $this->errorLog(ResultStatus::CITY_NOT_OPEN, '城市未开通');
    		$cityId=2;
    	}
    	$nowtime=date("Y-m-d H:i:s");
    	$list=Activity::query()
    	->where("city_id = $cityId and posion_banner <> '' and activity_state = 1 and activity_start_time < '$nowtime' and activity_end_time > '$nowtime'")
    	->execute()->toArray();
    	$count=0;
    	foreach ($list as $k=>$v){
    		$list[$k]['activity_cover']="http://img.meelier.com/".$list[$k]['activity_cover'];
    		if($list[$k]['out_link']==null){
    			$list[$k]['out_link']="";
    		}
    		if($list[$k]['activity_intro']==null){
    			$list[$k]['activity_intro']="";
    		}else{
    			$list[$k]['activity_intro'] = str_replace('src="/ueditor/php/upload/image/','src="http://meelier.com/ueditor/php/upload/image/', $list[$k]['activity_intro']);
    		} 
    		unset($list[$k]['activity_state']);
    		unset($list[$k]['activity_start_time']);
    		unset($list[$k]['activity_end_time']);
    		unset($list[$k]['activity_addtime']);
    		if($list[$k]['posion_banner']==5 || $list[$k]['posion_banner']==6 || $list[$k]['posion_banner']==7){
    			$count++;
    		}
    	}
    	if($count!=3){
    		foreach ($list as $k=>$v){
    			if($list[$k]['posion_banner']==5){
    				unset($list[$k]);
    			}elseif($list[$k]['posion_banner']==6){
    				unset($list[$k]);
    			}elseif($list[$k]['posion_banner']==7){
    				unset($list[$k]);
    			}
    		}	
    	}
    	$newarr=array();
    	foreach ($list as $val){
    		$newarr[]=$val;
    	}
        $this->setResult($newarr);
    }


}